﻿namespace K9Nano;

public class ApiResponse
{
    public int Code { get; set; }

    public string Message { get; set; } = "ok";

    public string? Error { get; set; }

    public object? Result { get; set; }

    public ApiResponse()
    {
    }

    public ApiResponse(int code, string message, string? error = null)
    {
        Code = code;
        Message = message;
        Error = error;
    }

    public static ApiResponse FromDto(object dto)
    {
        return new ApiResponse
        {
            Result = dto
        };
    }

    public readonly static ApiResponse Ok = new ();

    public static ApiResponse BadRequest(string error)
    {
        return new ApiResponse
        {
            Code = 400,
            Message = error,
            Error = error
        };
    }

    public static ApiResponse Unauthorized(string error)
    {
        return new ApiResponse
        {
            Code = 403,
            Message = error,
            Error = error
        };
    }
}
